package ran.service.user.impl;

import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ran.domain.user.dto.UserDTO;
import ran.domain.user.dto.UserQueryDTO;
import ran.domain.user.entity.User;
import ran.domain.user.vo.UserVO;
import ran.enums.ResultCode;
import ran.exception.ServiceException;
import ran.mapper.user.UserMapper;
import ran.service.user.IUserService;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ran
 * Date: 2025-11-01
 * Time: 17:07
 */
@Service
@Slf4j
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<UserVO> list(UserQueryDTO userQueryDTO) {
        log.info("查询用户参数, userQueryDTO:{}",userQueryDTO);
        PageHelper.startPage(userQueryDTO.getPageNum(),userQueryDTO.getPageSize());// 引入分页插件,可以自动在查询条件下加入分页SQL语句
        return userMapper.selectUserList(userQueryDTO);
    }

    @Override
    public int updateStatus(UserDTO userDTO) {
        User user = userMapper.selectById(userDTO.getUserId());
        if (user == null) {
            throw new ServiceException(ResultCode.FAILED_USER_NOT_EXISTS);
        }
        user.setStatus(userDTO.getStatus());
        return userMapper.updateById(user);
    }


}
